//
//  MediaFansContentCell.m
//  YongChuanTradingArea
//
//  Created by Vivian on 2017/9/12.
//  Copyright © 2017年 李冰. All rights reserved.
//

#import "MediaFansContentCell.h"
#import "MediaFansCell.h"

static NSString * const MediaFansCellID = @"MediaFansCell";

@interface MediaFansContentCell ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, assign) NSInteger pageNumber;

@property (nonatomic, strong) NSMutableArray * dataArray;

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation MediaFansContentCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.pageNumber = 1;
        self.tableView.separatorInset = UIEdgeInsetsMake(0, 12, 0, 0);
        self.tableView.separatorColor = kLineColor;
        [self.tableView registerNib:[UINib nibWithNibName:MediaFansCellID bundle:[NSBundle mainBundle]] forCellReuseIdentifier:MediaFansCellID];
        [self layoutItems];
    }
    return self;
}

#pragma mark - lazyload
- (UITableView *)tableView {
    if (!_tableView) {
        //============== tableView ==============
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.backgroundColor = kBgColor;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.rowHeight = 100;
        // 分割线
        _tableView.separatorColor = kLightGrayColor;
        __weak typeof(self) weakSelf = self;
        //        _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        //            weakSelf.pageNumber = 1;
        //            [weakSelf requestDataWithType:weakSelf.type];
        //        }];
        //        _tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        //            weakSelf.pageNumber ++;
        //            [weakSelf requestDataWithType:weakSelf.type];
        //        }];
        [self.contentView addSubview:_tableView];
    }
    return _tableView;
}

- (NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = @[].mutableCopy;
    }
    return _dataArray;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    [self layoutItems];
}

- (void)layoutItems{
    self.tableView.sd_layout
    .leftEqualToView(self.contentView)
    .rightEqualToView(self.contentView)
    .topEqualToView(self.contentView)
    .bottomEqualToView(self.contentView);
}

- (void)requestDataWithType:(NSString *)type{
    
}

#pragma mark - tableview delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MediaFansCell * cell = [tableView dequeueReusableCellWithIdentifier:MediaFansCellID forIndexPath:indexPath];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

@end
